package com.darren.euc.entity;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.darren.euc.util.SerializeUtil;

@Entity
@Table(name = "euc_login_validate")
public class LoginValidate implements Serializable {

	private static final long serialVersionUID = 5810717084282992133L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	@Column(name = "user_id")
	private Integer userId;
	
	@Column(name = "login_time")
	private Date loginTime;

	@Column(name = "expired_time")
	private Integer expiredTime;

	@Column(name = "record_status")
	private String recordStatus;

	@Column(name = "application_session")
	private byte[] appSession;

	@Transient
	private AppSession applicationSession;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	public Integer getExpiredTime() {
		return expiredTime;
	}

	public void setExpiredTime(Integer expiredTime) {
		this.expiredTime = expiredTime;
	}

	public String getRecordStatus() {
		return recordStatus;
	}

	public void setRecordStatus(String recordStatus) {
		this.recordStatus = recordStatus;
	}

	public byte[] getAppSession() {
		return appSession;
	}

	public void setAppSession(byte[] appSession) {
		this.appSession = appSession;
	}

	public AppSession getApplicationSession() throws ClassNotFoundException, IOException {
		if(applicationSession == null && appSession != null){
			applicationSession = (AppSession) SerializeUtil.deserializeObject(appSession);
		}
		return applicationSession;
	}

	public void setApplicationSession(AppSession applicationSession) throws IOException {
		if(applicationSession != null){
			appSession = SerializeUtil.serializeObject(applicationSession);
		}
		this.applicationSession = applicationSession;
	}
	
}
